﻿@using KMF.WebUI.Areas.KMFadmin.Models
@using KMF.WebUI.Areas.KMFadmin.CustomHelpers
@model List<KMF.Common.ProductCategoryMapLinkDto>
@{
    ViewBag.Title = "Danh sách liên kết danh mục";
    Layout = "~/Areas/KMFadmin/Views/Shared/_layout.cshtml";
}

@section LeftMenu
{
    <div id="left">
        <div class="LeftMenuWraper">
            <div class="leftMenuHeader">
                <span style="padding-left: 10px;">
                    <strong>Truy cập nhanh</strong>
                </span>
            </div>
            <ul id="p-quick-menu" class="quick-menu">
                <li class="qmn-info-pro">
                    <a href="@Url.Action("Index", "AdminProductCategory")">Thông tin danh mục</a>
                </li>
                <li class="qmn-info-pro">
                    <a href="@Url.Action("CategoryBanner", "AdminProductCategory")">Banners category</a>
                </li>
                <li class="qmn-info-pro">
                    <a href="@Url.Action("TemplateList", "AdminProductCategory")">Template danh mục</a>
                </li>
                <li class="qmn-info-pro">
                    <a href="@Url.Action("Index", "AdminProductCategoryMapLink")">Liên kết danh mục</a>
                </li>
            </ul>
            <div class="leftMenuFooter"></div>
        </div>
    </div>
    <!-- END #left -->
}
<nav>
    <div id="jCrumbs" class="breadCrumb module">
        <ul>
            <li><a href="@Url.Action("Index","AdminHome")"><i class="bootstrap icon-home"></i></a></li>
            <li><a href="javascript:void(0)">Danh sách khách hàng</a> </li>
        </ul>
    </div>
</nav>
<div class="toolBox">
    @Html.ToolBox(new List<object> { new Add { ClassCss = "Add", ActionName = "/KMFadmin/AdminProductCategoryMapLink/Add" } })
</div>
<div>
    @Html.DropDownList("CategoryList", new SelectList(ViewBag.MenuList, "Id", "Name"), new { })
</div>

@{
    var arr = new string[] { "top", "left", "right", "bottom" };
    var chk = false;
    for (int i = 0; i < arr.Length; i++)
    {
        var listModel = from c in Model where c.Position == arr[i] orderby c.Ordering descending select c;
        if (listModel.Any())
        {
            chk = true;
            var count = 0;
            <table class="table-odd table-plist" style="margin-top: 20px;">
                <tr>
                    <th style="width:30px;">STT</th>
                    <th>Tên danh mục</th>
                    <th style="width:50px;">Vị trí</th>
                    <th style="width:70px;">Hiển thị</th>
                    <th style="width:80px;">Trạng thái</th>
                </tr>
                @if (Model.Any())
                {
                    foreach (var item in listModel)
                    {
                        count++;
                        <tr>
                            <td style="text-align:center;">@count</td>
                            <td>
                                @item.Name
                            </td>
                            <td style="text-align:center;">
                                @item.Position
                            </td>
                            <td style="text-align:center;">
                                <input type="checkbox" name="chkShow" @string.Format("{0}", item.Active ? "checked='checked'" : "") />
                            </td>
                            <td style="text-align:center;">
                                <a href="@Url.Action("Edit", "AdminProductCategoryMapLink", new { id = @item.Id })">Edit</a> |
                                <a href="javascript:void(0);" idata="@item.Id" onclick="DeleteProductCategoryMapLink(this)">Xóa</a>
                            </td>
                        </tr>
                    }
                }
            </table>
        }

    }
    if (!chk)
    {
        <table class="table-odd table-plist" style="margin-top: 20px;">
            <tr>
                <th style="width:30px;">STT</th>
                <th>Tên danh mục</th>
                <th style="width:50px;">Vị trí</th>
                <th style="width:70px;">Hiển thị</th>
                <th style="width:80px;">Trạng thái</th>
            </tr>
        </table>
    }

}

@section scripts
{
    <script type="text/javascript">
        function DeleteProductCategoryMapLink(cmd) {
            var cmd = $(cmd);
            if (confirm('Bạn có thực sự muốn xóa khách hàng này')) {
                $.ajax({
                    url: '/KMFadmin/AdminProductCategoryMapLink/DeleteProductCategoryMapLink',
                    data: { id: cmd.attr('idata') },
                    success: function (data) {
                        if (data > 0) {
                            cmd.parent().parent().fadeOut();
                        } else {
                            alert('Xóa danh mục thất bại!');
                        }
                    },
                    error: function () {
                        alert('Đã có lỗi xảy ra!');
                    }
                });
            }
        }

        $(function () {
            $('#CategoryList').change(function () {
                location.href = '/KMFadmin/AdminProductCategoryMapLink/ShowByCate?category=' + $(this).val();
            });

            var cate = '@ViewBag.CategoryId';
            if (cate != '0') {
                $('#CategoryList option[value$=@ViewBag.CategoryId]').attr('selected', 'selected');
            } else {
                location.href = '/KMFadmin/AdminProductCategoryMapLink/';
            }
            
        });
    </script>
}




